<?php

namespace App\Http\Service;

use App\Http\Repository\OrderRepository;
use App\Http\Criteria\PaginateCriteria;
use App\Http\Criteria\OrderByCreatedAtCriteria;
use Illuminate\Support\Facades\DB;

class OrderService extends BaseService
{
    protected $rep;

    public function __construct(OrderRepository $repository)
    {
        $this->rep = $repository;
    }

    public function list($user, $page = 1) {

        $this->rep->pushCriteria(new OrderByCreatedAtCriteria());
        $this->rep->pushCriteria(new PaginateCriteria($page));

        return $this->rep->with('goods')->findByFields(['user_id' => $user->id]);
    }
}
